// pages/mine/pages/my/afterSales/afterSales.js
const util = require('../../../../../utils/util');
const request = require('../../../../../utils/request')
const WxParse = require('../../../../../wxParse/wxParse/wxParse.js')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        baseUrl:request.BASE_URL,
        navbarHeight: 0,
        page:1,
        limit:10,
        isLastPage:false,
        list:[],
        can_withdraw: 0,
        withdraw_days: '',
        userInfo:{}
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            navbarHeight: util.getNavbarHeight(),
            userInfo: wx.getStorageSync('userInfo')
        })

    },
    toBack() {
        wx.navigateBack()
    },
    hideAgreeClose(){
      this.setData({
        showAgreement: !this.data.showAgreement
      })
    },
    tabClick(e) {
        const index = e.currentTarget.dataset.index;
        let item = e.currentTarget.dataset.item;
        this.setData({
            currentTab: index,
            status: item.status,
            page: 1,
            list: [],
            isLastPage: false,
        })
        this.getList()
    },
    toWithdrawal() {
      if(!this.data.can_withdraw){
        this.setData({
          isShowWindow: !this.data.isShowWindow
        })
      }else{
        wx.navigateTo({
          url: '/pages/mine/pages/my/withdrawal/withdrawal',
        })
      }
    },
    hideWindow(){
      this.setData({
        isShowWindow: !this.data.isShowWindow
      })
    },
    getList() {
        let _this = this
        request._post('/api?method=user.userAccount', {
            page: this.data.page,
            limit: this.data.limit,
        }).then(res => {
            if (res.data.list.length == 0 || res.data.list == null) {
                _this.setData({
                    isLastPage: true,
                })
            }
            _this.setData({
              withdraw_rule: res.data.withdraw_rule,
              withdraw_days: res.data.withdraw_days,
              can_withdraw: res.data.can_withdraw,
              list: _this.data.list.concat(res.data.list)
            })
            WxParse.wxParse('detail_content', 'html',res.data.withdraw_rule, _this, 5);
        })
       
    },
    // 上拉加载
    onReachBottom: function () {
        if (this.data.isLastPage) {
            return
        }
        let page = this.data.page
        page++
        this.setData({
            page,
        })
        this.getList()
    },
       // 获取个人信息
       getUserInfo() {
        let _this = this
        request._get('/api?method=user.info', {},'noload').then(res => {
            // console.log(res, '个人信息')
            _this.setData({
                userInfo: res.data,
              
            })
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.setData({
            isLastPage: false,
            page:1,
            limit:10
        })
        this.getList()
        this.getUserInfo()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})